<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://www.ufida.com/multilang" prefix="ml" %>
<%@ taglib uri="http://www.ufida.com/lfw" prefix="lfw" %>
<html> 
	<head>
		<lfw:base/>
		<lfw:head/>
		<link rel='STYLESHEET' type='text/css' href='${ROOT_PATH}/html/nodes/login/themes/webclassic/stylesheets/loginbutton.css'>
		<lfw:import/>
	</head>
	<body leftmargin="0" topmargin="0" scroll="yes" onload="pageBodyScript();">
		<lfw:pageModel className="nc.lfw.finance.login.WebbxLoginPageModel" modelId="ncsimlogin" >
			<lfw:layout type="flowv" border="0">
				<lfw:layoutPanel height="10">
					&nbsp;
				</lfw:layoutPanel>
				<lfw:layoutPanel height="75">
					<lfw:form id="nclogin_form"/>
				</lfw:layoutPanel>
				<lfw:layoutPanel>
					<lfw:layout type="flowh" border="0">
						<lfw:layoutPanel width="30">
			       			&nbsp;
			       		</lfw:layoutPanel>
			            <lfw:layoutPanel width="30" height="20">
			       			<lfw:button id="submitBtn"/>
			       		</lfw:layoutPanel>
			       		<lfw:layoutPanel width="30">
			       			<lfw:button id="optionBtn"/>
			    		</lfw:layoutPanel>
					</lfw:layout>		
				</lfw:layoutPanel>
			</lfw:layout>
		</lfw:pageModel>
	</body>
</html>
<script>
function afterPageInit() 
{
	var ds = getDataset('nclogin_ds');
	ds.setRowSelected(0);
	var form = getComponent("nclogin_form"); 
	otherPageInit();
}
function otherPageInit(){
	var ds = getDataset('nclogin_ds');
	window.$nc_corp_datasource = getSessionAttribute('defaultDatasource');
	window.$lastDatasourceName = window.$nc_corp_datasource;
	var form = getComponent('nclogin_form');
	var refComponent = form.getElement('corpName');
	
	/**
	 * 参照框打开时设置当前帐套对应数据源
	 */
	refComponent.beforeOpenRefDialog = function()
	{	
		if(window.$nc_corp_accountcode == null)
			return 'sys_datasource=' + window.$nc_corp_datasource;
		
		if(window.$lastDatasourceName != window.$nc_corp_datasource){     
			this.setRefresh(true);
			window.$lastDatasourceName = window.$nc_corp_datasource;
		}
		// 记录参照上次的ds
		window.$lastDatasourceName = window.$nc_corp_datasource;
		return 'sys_datasource=' + window.$nc_corp_datasource;
	}
	
	/**
	 * 监测帐套数据的改变
	 */
	ds.onAfterDataChange = function(event)
	{
		if(event.cellColIndex == this.nameToIndex('accountCode'))
		{
			//帐套改变则清空其它
			if(event.currentValue != event.oldValue){
				ds.setValueAt(0,ds.nameToIndex("corpCode"),null);
				ds.setValueAt(0,ds.nameToIndex("corpName"),null);
				ds.setValueAt(0,ds.nameToIndex("userId"),null);
			}
			
			var row = this.getSelectedRow();
			var account = row.getCellValue(this.nameToIndex('accountCode'));
			if(account != null) {
				window.$nc_corp_accountcode = account;
			}
			
			// 建立帐套和数据源的对应关系
			if(window.$accountDsMap == null)
				window.$accountDsMap = new HashMap();
			var currentDatasource = window.$accountDsMap.get(window.$nc_corp_accountcode);	
			if(currentDatasource == null) 
			{ 
				var cmd = new CommonCommand('findDatasourceByAccountCode');
				cmd.setParameter('accountCode=' + window.$nc_corp_accountcode);
				cmd.setAsync(false);
				var resultDs = cmd.exec();
				currentDatasource = resultDs[0];
				window.$accountDsMap.put(window.$nc_corp_accountcode, currentDatasource);
			}
			// 设置当前数据源
			window.$nc_corp_datasource = currentDatasource;
			//alert("设置当前数据源:" + window.$nc_corp_datasource);
		}	
	}
}
function beforeProcessReferenceEnter(ref) {
	return "datasource=" + window.$nc_corp_datasource;
}
function valid()
{
	var form = getComponent("nclogin_form");
	var div = document.getElementById("$d_nclogin_formaccountCode");
	var ds = getDataset("nclogin_ds");
	var row = ds.getRow(0);
	parent.valid4SimpleLogin([row.getCellValue(ds.nameToIndex('accountCode')),row.getCellValue(ds.nameToIndex('corpCode'))]);
	parent.hideDialog('login2dlg');
}
</script>